﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YiMeiJiaService.IService;
using YiMeiJiaService.Assembly;
using YiMeiJiaLibModel.Assembly;
using YiMeiJiaLibModel.Business;
using System.Text.Json.Serialization;
using Newtonsoft.Json;
using System.Dynamic;
using YiMeiJiaService.Assembly.DB;
using YiMeiJiaLibModel.Business.Dto;

namespace YiMeiJiaService.Service
{
    public class Goods : IGoods
    {
        public async Task<List<WxGoodCategoryDto>> GetAllCategories(string msg)
        {
            var response = await _HttpClient.Action<List<WxGoodCategoryDto>>("GetAllCategories", new { });
            if (response.status)
            {
                if (string.IsNullOrEmpty(msg))
                {
                    return response.data.Take(4).OrderByDescending(x => x.sort).ToList();
                }
                else
                {
                    return response.data;
                }
                
            }
            msg = response.msg;
            return  new List<WxGoodCategoryDto>();
        }

        public async  Task<CoreCmsGoodsDto> GetGoodDetail(int id)
        {
            var response = await _HttpClient.Action<CoreCmsGoodsDto>("获取商品详情", new { id});
            if (response.status)
                return response.data;
            return new CoreCmsGoodsDto();

        }

        public async Task<List<GoodListDTO>> GetGoodsRecommendList(  string msg)
        {
            var response = await _HttpClient.Action<List<GoodListDTO>>("获取随机推荐商品",   new   { });
            msg = response.msg;
            if (response.status)
            {
               return response.data;
            }
            msg = response.msg;
            return new List<GoodListDTO>();
        }
    }
}
